<? require("core/base.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>uptime - records</title>
<link href="files/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><a href="index.php"><img src="img/hdr.png" alt="uptime" width="800" height="100" hspace="0" vspace="0" border="0"></a></td>
  </tr>  
  <tr>  
    <td valign="top" class="fons33"><?optionBar();?></td>
  </tr>
  <tr>  
    <td valign="top" class="fons33b">
      <table width="100%" border="0" cellspacing="0" cellpadding="8">
        <tr>
          <td><p><br>
              <span class="destacat"><br>
              <br>
              Records</span></p>
            <p></a><br>
            </p>
            <table width="780" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td width="195" class="hdrtaula">Description</td>
                <td width="180" class="hdrtaula">Value</td>
                <td width="98" class="hdrtaula">User</td>
                <td width="145" class="hdrtaula">Machine</td>				
                <td width="146" class="hdrtaula">Date</td>
              </tr>
              <?
	$bd=new bd;
	
	// Highest uptime ever
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Highest confirmed uptime ever</TD>");
	$sQuery="SELECT username, MAX(uptime) AS m, reg_date, machine FROM uptime GROUP BY username, reg_date, machine ORDER BY m DESC LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime($r[0]->m)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->machine)."</TD>");	
	echo("<TD class=\"celltaula\">".niceDate($r[0]->reg_date)."</TD>");	
	echo("</TR>");
	
	
	// Lowest uptime ever
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Lowest confirmed uptime ever</TD>");
	$sQuery="SELECT username, MIN(uptime) AS m, reg_date, machine FROM uptime GROUP BY username, reg_date, machine ORDER BY m LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime($r[0]->m)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->machine)."</TD>");		
	echo("<TD class=\"celltaula\">".niceDate($r[0]->reg_date)."</TD>");	
	echo("</TR>");	
	
	
	// Most rebooted machine
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Most rebooted machines</TD>");
	$sQuery="SELECT username, machine, COUNT(*) AS res FROM uptime GROUP BY username, machine ORDER BY res DESC";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();	
	echo("<TD class=\"celltaula\" colspan=\"4\">");
	$ant=-1;
	foreach ($r as $k => $v)
	{
		if ($v->res<$ant)
			break;
			
		echo("-<I>".webstr($v->machine)."</I>, (<I>".webstr($v->username)."</I>) with ");
		if ($v->res==1)
			echo("one reboot<BR>");
		else
			echo($v->res." reboots<BR>");
		
		$ant=$v->res;
	}
	echo("</TD>");	
	echo("</TR>");	


	// Least rebooted machine
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Least rebooted machines</TD>");
	$sQuery="SELECT username, machine, COUNT(*) AS res FROM uptime GROUP BY username, machine ORDER BY res";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();	
	echo("<TD class=\"celltaula\" colspan=\"4\">");
	$ant=-1;
	foreach ($r as $k => $v)
	{
		if ($v->res>$ant && $k!=0)
			break;
			
		echo("-<I>".webstr($v->machine)."</I>, (<I>".webstr($v->username)."</I>) with ");
		if ($v->res==1)
			echo("one reboot<BR>");
		else
			echo($v->res." reboots<BR>");
		
		$ant=$v->res;
	}
	echo("</TD>");	
	echo("</TR>");	
	
	
	// Highest avg uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Highest average uptime</TD>");
	$sQuery="SELECT u.username, AVG(u.uptime) AS m FROM uptime u GROUP BY u.username ORDER BY m DESC LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime(round($r[0]->m))."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">n/a</TD>");	
	echo("</TR>");	


	// Lowest avg uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Lowest average uptime</TD>");
	$sQuery="SELECT u.username, AVG(u.uptime) AS m FROM uptime u GROUP BY u.username ORDER BY m LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime(round($r[0]->m))."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">n/a</TD>");	
	echo("</TR>");	


	// Oldest user
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Oldest user</TD>");
	$sQuery="SELECT username, subscribe_date FROM users ORDER BY subscribe_date LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">User for ".niceUptime(time()-dateToTimestamp($r[0]->subscribe_date))."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">".webstr(niceDate($r[0]->subscribe_date))."</TD>");	
	echo("</TR>");	


	// Newest user
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Newest user</TD>");
	$sQuery="SELECT username, subscribe_date FROM users ORDER BY subscribe_date DESC LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">User for ".niceUptime(time()-dateToTimestamp($r[0]->subscribe_date))."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">".webstr(niceDate($r[0]->subscribe_date))."</TD>");	
	echo("</TR>");	
		
		
	// Highest accumulated uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Highest accumulated uptime</TD>");
	$sQuery="SELECT username, SUM(uptime) AS m FROM uptime GROUP by username ORDER BY m DESC LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime($r[0]->m)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">n/a</TD>");	
	echo("</TR>");		
	
	
	// Lowest accumulated uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Lowest accumulated uptime</TD>");
	$sQuery="SELECT username, SUM(uptime) AS m FROM uptime GROUP by username ORDER BY m LIMIT 1 OFFSET 0";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime($r[0]->m)."</TD>");
	echo("<TD class=\"celltaula\">".webstr($r[0]->username)."</TD>");
	echo("<TD class=\"celltaula\">n/a</TD>");		
	echo("<TD class=\"celltaula\">n/a</TD>");	
	echo("</TR>");		
	

?>
            </table>
            <p><br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
            </p>
	<DIV align="right">
      <a href="http://validator.w3.org/check?uri=referer"><img border="0"
          src="http://www.w3.org/Icons/valid-html401"
          alt="Valid HTML 4.01!" height="31" width="88"></a>
    </DIV>			
            <p>&nbsp;</p></td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
</body>
</html>
